package com.atguigu.gmall.all.controller;


import com.atguigu.gmall.client.UserFeignClient;
import com.atguigu.gmall.model.user.UserAddress;
import com.atguigu.gmall.order.client.OrderFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;
import java.util.Map;

@Controller
public class OrderController {

    @Autowired
    OrderFeignClient orderFeignClient;

    @Autowired
    UserFeignClient userFeignClient;

    @GetMapping("/trade.html")
    public String trade(Model model){
        List<UserAddress> userAddresses = userFeignClient.userAddressList();
        model.addAttribute("userAddressList",userAddresses);
        Map<String, Object> trade = orderFeignClient.trade();
        if (trade == null) {
            return "redirect:http://cart.gmall.com/cart.html";
        }
        model.addAllAttributes(trade);
        return "order/trade";
    }
}
